<?php

class youhuilist
{
public function index()
{
$root = array();
$root['return'] = 1;
$city_id = intval($GLOBALS['request']['city_id']);
$cate_id = intval($GLOBALS['request']['cate_id']);
$keyword = strim($GLOBALS['request']['keyword']);
$page = intval($GLOBALS['request']['page']);
$page=$page==0?1:$page;
$page_size = PAGE_SIZE;
$limit = (($page-1)*$page_size).','.$page_size;
$sql_count = 'select count(*) from '.DB_PREFIX.'youhui ';
$sql = 'select id, supplier_id as merchant_id,name as title,list_brief as content,icon as merchant_logo,create_time,xpoint,ypoint,address as api_address,icon as image_1 from '.DB_PREFIX.'youhui ';
$now = get_gmtime();
$where = '1 = 1 and is_effect = 1 and begin_time<'.$now.' and (end_time = 0 or end_time > '.$now.')';
if ($city_id >0)
$where .= " and city_id = $city_id";
if ($cate_id >0)
$where .= " and deal_cate_id = $cate_id";
if($keyword)
{
$kws_div = div_str($keyword);
foreach($kws_div as $k=>$item)
{
$kw[$k] = str_to_unicode_string($item);
}
$ukeyword = implode(' ',$kw);
$where.=" and match(name_match) against('".$ukeyword."'  IN BOOLEAN MODE) ";
}
$sql_count.=' where '.$where;
$sql.=' where '.$where;
$sql.=' limit '.$limit;
$total = $GLOBALS['db']->getOne($sql_count);
$page_total = ceil($total/$page_size);
$list = $GLOBALS['db']->getAll($sql);
$youhui_list = array();
foreach($list as $item){
$youhui_list[] = m_youhuiItem($item);
}
$root['item'] = $youhui_list;
$root['page'] = array('page'=>$page,'page_total'=>$page_total);
output($root);
}
}

?>